/**
 * Created by John on 2016/6/30.
 */
var MongoClient = require('mongodb').MongoClient;
var mongo = new MongoClient();
var microblog = null;

exports.connect = function (callback) {
    mongo.connect('mongodb://localhost', function (err, db) {
        microblog = db.db('microblog');
        if (err) {
            microblog.close();
            return callback(err);
        }
        callback(microblog);
    });
};

exports.error = function (err, callback) {
    if (microblog) {
        microblog.close();
    }
    if (err) {
       return callback(err);
    }
};

